<?php
namespace app\servermenu\service\menu;

use \app\manage\service\ApiBase;
/**
 * 如后台菜单管理,个人中心菜单等凡是用角色来区分的菜单,都在此进行管理
 * @author adv30 <adv30@126.com> 2017年7月6日11:37:38
 */
class AdminMenu extends ApiBase
{
    protected $adminMenuValidate = '\app\servermenu\validate\AdminMenu';
    protected $adminMenuLogic = '\app\servermenu\logic\AdminMenu';
    // 根据角色获取后台菜单
    public function get(): array
    {
        $data['app_key'] = $this->getAppKey();
        $data['token'] = $this->token;
        return $this->stepRun($data, 'serveruser/menu/Menu/treeByAppKey', 'get', 'get');
    }
    // 为某一角色增加某一菜单及其子菜单的(展示权限) 仅是可展示,该菜单及其子菜单的功能能否被访问,取决于权限是否被允许
    public function addShowMenuAndChildren(): array
    {
        $data = $this->haveIssetReceiveData(['role_id'=>'0', 'menu_id'=>'0']);
        return $this->oneStepRun($data, 'serveruser/menu/Menu/addShowMenuAndChildren', 'addShowMenuAndChildren');
    }
    // 为某一角色增加某一菜单的(展示权限) 仅是可展示,该菜单的功能能否被访问,取决于权限是否被允许
    public function addShowMenuAuthByRole(): array
    {
        $data = $this->haveIssetReceiveData(['role_id'=>'0', 'menu_id'=>'0']);
        return $this->oneStepRun($data, 'serveruser/menu/Menu/addShowMenuAuthByRole', 'addShowMenuAuthByRole');
    }
    // 增加一个非顶级菜单
    public function add(): array
    {
        $setArr = ['menu_cate_id'=>'0', 'name'=>' ', 'name_cn'=>' ', 'order'=>'100', 'type'=>'menu','url'=>'','merge_auth'=>'','auth_data'=>'{}',
            'auth_id'=>'1','pid'=>'0','level'=>'1'];
        $data = $this->haveIssetReceiveData($setArr);
        return $this->oneStepRun($data, 'serveruser/menu/Menu/add', 'add');
    }
    // 创建顶级菜单
    public function addTop(): array
    {
        $setArr = ['menu_cate_id'=>'0', 'name'=>' ', 'name_cn'=>' ', 'order'=>'100', 'type'=>'menu','url'=>'','merge_auth'=>'','auth_data'=>'{}', 'auth_id'=>'1'];
        $data = $this->haveIssetReceiveData($setArr);
        return $this->oneStepRun($data, 'serveruser/menu/Menu/addTop', 'addTop');
    }
    // 停止某一角色某一菜单的(展示权限)
    public function stopShowMenuAuthByRole(): array
    {
        $data = $this->haveIssetReceiveData(['id'=>'', 'role_id'=>'', 'menu_id'=>'']);
        if ($data['id'] === '' && ($data['role_id'] === '' || $data['menu_id'] === '')) {
            return verify_err($data, 'id或(menu_id,role_id)参数至少传一组');
        }
        return $this->oneStepRun($data, 'serveruser/menu/Menu/stopShowMenuAuthByRole', 'stopShowMenuAuthByRole');
    }
    // 启用某一角色某一菜单的(展示权限)
    public function startShowMenuAuthByRole(): array
    {
        $data = $this->haveIssetReceiveData(['id'=>'', 'role_id'=>'', 'menu_id'=>'']);
        if ($data['id'] === '' && ($data['role_id'] === '' || $data['menu_id'] === '')) {
            return verify_err($data, 'id或(menu_id,role_id)参数至少传一组');
        }
        return $this->oneStepRun($data, 'serveruser/menu/Menu/startShowMenuAuthByRole', 'startShowMenuAuthByRole');
    }
    // 获取某一菜单分类下的菜单树
    public function treeByCate(): array
    {
        $data = $this->haveIssetReceiveData(['menu_cate_id'=>'0']);
        return $this->oneStepRun($data, 'serveruser/menu/Menu/treeByCate', 'treeByCate');
    }
    // 移动某一菜单记录及其子记录到另一记录下
    public function move(): array
    {
        $data = $this->haveIssetReceiveData(['id'=>'0', 'pid'=>'0']);
        return $this->oneStepRun($data, 'serveruser/menu/Menu/move', 'move');
    }
    // 停止某一角色某一菜单及其可用子菜单的(展示权限)
    public function stopShowMenuAndChildren(): array
    {
        $data = $this->haveIssetReceiveData(['id'=>'', 'role_id'=>'', 'menu_id'=>'']);
        if ($data['id'] === '' && ($data['role_id'] === '' || $data['menu_id'] === '')) {
            return verify_err($data, 'id或(menu_id,role_id)参数至少传一组');
        }
        return $this->oneStepRun($data, 'serveruser/menu/Menu/stopShowMenuAndChildren', 'stopShowMenuAndChildren');
    }
    // 启用某一角色某一菜单及其可用子菜单的(展示权限)
    public function startShowMenuAndChildren(): array
    {
        $data = $this->haveIssetReceiveData(['id'=>'', 'role_id'=>'', 'menu_id'=>'']);
        if ($data['id'] === '' && ($data['role_id'] === '' || $data['menu_id'] === '')) {
            return verify_err($data, 'id或(menu_id,role_id)参数至少传一组');
        }
        return $this->oneStepRun($data, 'serveruser/menu/Menu/startShowMenuAndChildren', 'startShowMenuAndChildren');
    }
        // 编辑某一菜单记录
    public function edit(): array
    {
        $data = $this->haveIssetReceiveData(['id'=>'0', 'name'=>'', 'name_cn'=>'', 'menu_cate_id'=>'', 'pid'=>'','order'=>'', 'level'=>'']);
        if (array_eq($data, '', ['name', 'name_cn', 'menu_cate_id', 'pid', 'order', 'level'])) {
            return verify_err($data, 'name,name_cn,menu_cate_id,pid,order,level至少要传一个');
        }
        return $this->oneStepRun($data, 'serveruser/menu/Menu/edit', 'edit');
    }
}